import axios from 'axios'
axios.defaults.baseURL = 'http://124.222.34.94:8080/admin';

 
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    let token=sessionStorage.getItem('token');
    //Authorization或者是token
    token && (config.headers.token=token);
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    //console.log('res1',response);
    switch(response.data.code){
        case 401:
            alert('token失效');
             
            window.location.href='http://localhost:5173/'
    }
    return response;
  }, function (error) {
    //console.log('res2',error)
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });
export default axios;